/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package holdem.network;

import holdem.Card;
import holdem.pokergui.MessageReceiverInGUI;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.*;


/**
 *
 * @author Anders
 */
public abstract class NetworkEvent implements Serializable
{
    @Override
    public String toString() {
        String className = this.getClass().getSimpleName();
        String all = "[" + className;
        for(Field f : this.getClass().getDeclaredFields()) {
            f.setAccessible(true);
            String fieldName = f.getName();
            try {
                fieldName += " " + f.get(this).toString();
            } catch (Exception ex) {
            }
            all += "|" + fieldName;
        }
        all += "]";
        return all;
    }
     public abstract void event(MessageReceiverInGUI msg);
     }

class ChangeTurnEvent extends NetworkEvent
{
    private Integer playerID;

    public ChangeTurnEvent(Integer playerID)
    {
        this.playerID = playerID;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.changeTurn(playerID);
    }
}

class FoldEvent extends NetworkEvent
{
    public Integer playerID;

    public FoldEvent(Integer playerID)
    {
        this.playerID = playerID;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.fold(playerID);
    }
}
class CheckEvent extends NetworkEvent
{
    public Integer playerID;

    public CheckEvent(Integer playerID)
    {
        this.playerID = playerID;
    }
    
    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.check(playerID);
    }
}

class RaiseEvent extends NetworkEvent
{
    public Integer playerID, amount;

    public RaiseEvent(Integer playerID, Integer amount)
    {
        this.playerID = playerID;
        this.amount = amount;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        //msg.raise(playerID, amount);
    }
}


    ////////
    ////////
    ///////
    //////




class RevealPlayerHandEvent extends NetworkEvent
{
    Map<Integer, List <Card>> mp;

    public RevealPlayerHandEvent(Map<Integer, List<Card>> mp)
    {
        this.mp = mp;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.revealPlayerHand(mp);
    }
}
class BetEvent extends NetworkEvent
{
    public Integer playerID, amount;

    public BetEvent(Integer playerID, Integer amount)
    {
        this.playerID = playerID;
        this.amount = amount;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.bet(playerID, amount);
    }
}
class ShowDown extends NetworkEvent
{
    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.showDown();
    }
}

class SplitPot extends NetworkEvent
{
    @Override
    public void event(MessageReceiverInGUI msg)
    {
        //msg.splitPot();
    }
}


class DealTableCardEvent extends NetworkEvent
{
    public Card card;

    public DealTableCardEvent(Card card)
    {
        this.card = card;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.dealTableCard(card);
    }
}

class MoneyGainEvent extends NetworkEvent
{
    public Integer playerID, amount;

    public MoneyGainEvent(Integer playerID, Integer amount)
    {
        this.playerID = playerID;
        this.amount = amount;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.moneyGain(playerID, amount);
    }
}

class DealerChangeEvent extends NetworkEvent
{
    private Integer playerID;

    public DealerChangeEvent(Integer playerID)
    {
        this.playerID = playerID;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.dealerChange(playerID);
    }
}
class RevealPlayerHand extends NetworkEvent
{
    public Integer playerID, amount;

    public RevealPlayerHand(Integer playerID, Integer amount)
    {
        this.playerID = playerID;
        this.amount = amount;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.revealPlayerHand(null);
    }
}



class GameStartEvent extends NetworkEvent
{
    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.gameStart();
    }
}

class GameEndEvent extends NetworkEvent
{
    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.gameEnd();
    }
}

class UserQuit extends NetworkEvent
{
    private Integer playerID;

    public UserQuit(Integer playerID)
    {
        this.playerID = playerID;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        //msg.inactive(playerID);
    }
}


class PlayerJoinEvent extends NetworkEvent
{
    public Integer playerID, amount;
    private String name;

    public PlayerJoinEvent(Integer playerID, Integer amount, String name)
    {
        this.playerID = playerID;
        this.amount = amount;
        this.name = name;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.newPlayer(playerID, name, amount);
    }
}
class PlayerJoinAccepted extends NetworkEvent
{
    public Integer playerID;

    public PlayerJoinAccepted(Integer playerID)
    {
        this.playerID = playerID;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.joinAccpted(playerID);
    }
}



class BigBlindIncreaseEvent extends NetworkEvent
{
    private Integer amount, playerID;

    BigBlindIncreaseEvent(Integer playerID, Integer amount)
    {
        this.amount = amount;
        this.playerID = playerID;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.bigBlindIncrease(playerID, amount);
    }

}

class SmallBlindIncreaseEvent extends NetworkEvent
{
    private Integer amount, playerID;

    SmallBlindIncreaseEvent(Integer playerID, Integer amount)
    {
        this.amount = amount;
        this.playerID = playerID;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.smallBlindIncrease(playerID, amount);
    }
}

class DealHandCardEvent extends NetworkEvent
{
    private Integer playerID;
    private Card[] handCards;

    public DealHandCardEvent(Integer playerID, Card[] handCards)
    {
        this.playerID = playerID;
        this.handCards = handCards;
    }

    @Override
    public void event(MessageReceiverInGUI msg)
    {
        msg.dealHandCard(handCards);
    }
}